﻿using System;
using UnityEditor;
using UnityEngine;

namespace SGEngine.ProfilerEx
{
    /// <summary>
    /// 复选择窗口
    /// </summary>
    public class MultiOptionSelectWindow : EditorWindow
    {
        public struct OptionItem
        {
            public string Msg;
            public bool IsSelect;

            public OptionItem(string msg, bool isSelect)
            {
                Msg = msg;
                IsSelect = isSelect;
            }
        }
        
        private OptionItem[] m_Options;
        private Action m_SelectedCallBack;
        
        public static void ShowWindow(string title, ref OptionItem[] options, Action callback)
        {
            var win = GetWindow<MultiOptionSelectWindow>(title);
            win.m_Options = options;
            win.m_SelectedCallBack = callback;
            win.Show();
        }
        
        private void OnGUI()
        {
            for (int i = 0; i < m_Options.Length; i++)
            {
                m_Options[i].IsSelect = EditorGUILayout.Toggle(m_Options[i].Msg, m_Options[i].IsSelect);
            }
            if (GUILayout.Button("确定"))
            {
                this.Close();
            }
        }

        private void OnDestroy()
        {
            m_SelectedCallBack?.Invoke();
        }
    }
}